Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable clippy error around generated main function #3850

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

vic1707
Copy link
Contributor

@vic1707 vic1707 commented Feb 4, 2025

The current implementation of embassy_executor::main and generated code causes clippy to complain even when using an empty function (for demonstration purposes).
image

error: future cannot be sent between threads safely
  --> src/main.rs:22:1
   |
22 | #[embassy_executor::main]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `____embassy_main_task` is not `Send`
   |
note: captured value is not `Send`
  --> src/main.rs:23:15
   |
23 | async fn main(_spawner: Spawner) {}
   |               ^^^^^^^^ has type `embassy_executor::Spawner` which is not `Send`
   = note: `*mut ()` doesn't implement `core::marker::Send`
note: captured value is not `Send`
  --> src/main.rs:23:15
   |
23 | async fn main(_spawner: Spawner) {}
   |               ^^^^^^^^ has type `embassy_executor::Spawner` which is not `Send`
   = note: `*mut ()` doesn't implement `core::marker::Sync`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send
   = note: `-D clippy::future-not-send` implied by `-D clippy::nursery`
   = help: to override `-D clippy::nursery` add `#[allow(clippy::future_not_send)]`

Currently the only way to make said error/warning go away is to put

#![allow(clippy::future_not_send)]

at the top of the module calling embassy_executor::main.
Users unfortunately can't put the allow attribute like this (attribute gets removed during expansion).

#[embassy_executor::main]
#[allow(clippy::future_not_send)]
async fn main(_spawner: Spawner) {}

nor

#[allow(clippy::future_not_send)]
#[embassy_executor::main]
async fn main(_spawner: Spawner) {}

Adding the attribute directly in the expanded code makes clippy happy.

Note: This might not be the ideal fix (maybe allowing async fn main(_spawner: SendSpawner) {} would work but I don't have enough knowledge on embassy to know if that's faceable or wished).
Adding the attribute seems like a good compromise, being quick and easy to maintain (maybe using expect can be better but it requires a relatively new version of rust)

Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

(clippy::future_not_send is a very dubious lint anyway especially for embedded. Many futures are not Send in embedded, and that's perfectly okay!)

@Dirbaio Dirbaio added this pull request to the merge queue Feb 4, 2025
Merged via the queue into embassy-rs:main with commit f663f3b Feb 5, 2025
10 checks passed
@vic1707
Copy link
Contributor Author

vic1707 commented Feb 5, 2025

Thank you, I certainly wasn't expecting a reply that quickly!

(clippy::future_not_send is a very dubious lint anyway especially for embedded. Many futures are not Send in embedded, and that's perfectly okay!)

Thank you for the advice! First time doing embedded and async in Rust so I'll keep that in mind 👌

@vic1707 vic1707 deleted the patch-1 branch February 6, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants